package com.xiaoming.api;

import com.xiaoming.Homework3Bootstrap;
import com.xiaoming.entity.DatabaseConfig;
import com.xiaoming.entity.User;
import com.xiaoming.service.UserServiceImpl;
import com.xiaoming.zk.CuratorServer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.sql.SQLException;
import java.util.List;

@RestController
public class Homework3Controller {
    @Autowired
    private UserServiceImpl userService;

    @RequestMapping("/user")
    public List<User> getUser() throws SQLException {
        return userService.findAll();
    }

    @RequestMapping("/change")
    public  String change() throws Exception {
        DatabaseConfig database = new DatabaseConfig();
        database.setJdbcUrl("jdbc:mysql://192.168.92.2:3398/hub_test?characterEncoding=utf8&useSSL=false");
        database.setUsername("root");
        database.setPassword("123456");
        database.setDriverClassName("com.mysql.jdbc.Driver");
        CuratorServer.getInstance().setData(database);
        return "修改成功";
    }

}
